package com.lhn.bbs.service.impl;

import com.lhn.bbs.dto.ActionResult;
import com.lhn.bbs.entity.Plate;
import com.lhn.bbs.mapper.PlateDao;
import com.lhn.bbs.service.PlateService;
import com.lhn.bbs.vo.PlateVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class PlateServiceImpl  implements PlateService {

    @Autowired(required=false)
    private PlateDao plateDao ;

    /**
     * 查询所有的板块
     * @return
     */
    @Override
    public ActionResult findPlates() {
        try{
            List<PlateVo> plateList =plateDao.findAll();
            for(PlateVo plateVo : plateList){
               int  count =  plateDao.findPlateCount(plateVo.getId());
               plateVo.setPlatethemenumber(count);
            }
            return new ActionResult(200,"success",plateList,null);
        }catch (Exception e ){
            log.error("====="+e.getMessage());
            return new ActionResult(201,"失败",null,null);
        }
    }
//   添加板块
    @Override
    public ActionResult addPlate(Plate plate) {

        try{
            long i = plateDao.insertPlate(plate);
//            log.error("====="+plateList);
            return new ActionResult(200,"success",null,null);
        }catch (Exception e ){
            log.error("====="+e.getMessage());
            return new ActionResult(201,"失败",null,null);
        }
    }

    @Override
    public ActionResult deleteplate(Integer plateid) {
        try{
            long i = plateDao.deleteByplateid(plateid);

            return new ActionResult(200,"success",null,null);
        }catch (Exception e ){
            log.error("====="+e.getMessage());
            return new ActionResult(201,"失败",null,null);
        }

    }
}
